package com.icexxx.db_column;

import java.util.Collection;
import java.util.Iterator;

import javax.sql.DataSource;

import cn.hutool.core.util.StrUtil;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.db.meta.Column;
import cn.hutool.db.meta.MetaUtil;
import cn.hutool.db.meta.Table;

/**
 * Hello world!
 *
 */
public class App {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        String tableName = "t_user";
        DataSource dataSource = DSFactory.get();
        StringBuilder sb = new StringBuilder();
        Table tableMeta = MetaUtil.getTableMeta(dataSource, tableName);
        String comment = tableMeta.getComment();
        sb.append("==============================\r\n");
        sb.append("" + comment + ">>" + tableName + "\r\n");
        Collection<Column> columns = tableMeta.getColumns();
        Iterator<Column> iterator = columns.iterator();
        while (iterator.hasNext()) {
            Column column = iterator.next();
            String name = column.getName();
            String typeName = column.getTypeName();
            String columnComment = column.getComment();
//                int type = column.getType();
//                JdbcType typeEnum = column.getTypeEnum();
            long length = column.getSize();
            String lower = StrUtil.toCamelCase(name);
            String upper = StrUtil.upperFirst(lower);
            String lowerCase = name.toLowerCase();
            String upperCase = name.toUpperCase();
            String analysis = StringUtil.analysis(name);
            System.out.println("name = " + name);
            System.out.println("lower = " + lower);
            System.out.println("upper = " + upper);
            System.out.println("lowerCase = " + lowerCase);
            System.out.println("upperCase = " + upperCase);
            System.out.println("analysis = " + analysis);
            String sql = "${abbreviation}.${name} ${lower},";
            sql = sql.replace("${name}", name);
            sql = sql.replace("${lower}", lower);
            sql = sql.replace("${upper}", upper);
            sql = sql.replace("${lowerCase}", lowerCase);
            sql = sql.replace("${upperCase}", upperCase);
            sql = sql.replace("${abbreviation}", analysis);
            System.out.println(sql);
            System.out.println("====================");
        }
    }
}
